package main.java.properties;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class PropertiesProvider {

	private String PROPERTY_FILE="simulateur.properties";
	static public PropertiesProvider propertiesProvider= new PropertiesProvider();
	private java.util.Properties prop = Properties.getInstance();

	private PropertiesProvider() {
	}
	
	public PropertiesProvider(String path){
		this.PROPERTY_FILE=path;		
	}

	public void write(String propertyName, String propertyContent) {
		try {
			
			prop.setProperty(propertyName, propertyContent);
			FileOutputStream out=new FileOutputStream(PROPERTY_FILE);
			prop.store(out,null);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String read(String property) {
		String result = "";
		FileInputStream input ;
		try {
			input=new FileInputStream(PROPERTY_FILE);
			prop.load(input);
			result = prop.getProperty(property);
			input.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return result;
	}
}
